import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)
// 导入其余8个路由组件
// 引入多个动态路由模块
import approvalsRouter from './modules/approvals'
import departmentsRouter from './modules/departments'
import employeesRouter from './modules/employees'
import permissionRouter from './modules/permission'
import attendancesRouter from './modules/attendances'
import salarysRouter from './modules/salarys'
import settingRouter from './modules/setting'
import socialRouter from './modules/social'
/* Layout 首页 */
import Layout from '@/layout'
// 1.constantRoutes 静态路由表
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'dashboard' }
    }]
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]
// 2.动态路由表asyncRoutes
export const asyncRoutes = [
  // {
  //   path: '/approvals',
  //   // 要想所有的功能页面中都包含左侧菜单及顶部导航条，需要将它们设置成**layout的子路由**。
  //   component: Layout,
  //   children: [
  //     {
  //       path: '', // 默认路由， path 为空，是默认展示此组件，或者说白了，这个配置项的路由就是 /approvals
  //       name: 'approvals',
  //       component: () => import('@/views/approvals'),
  //       meta: { title: 'approvals', icon: 'approvals' }
  //     }
  //   ]
  // }
  departmentsRouter,
  settingRouter,
  employeesRouter,
  permissionRouter,
  approvalsRouter,
  attendancesRouter,
  salarysRouter,
  socialRouter
]
// 对路由进行实例化,合并静态和动态路由表
const createRouter = () => new Router({
  // 控制路由滚动行为  滚动到顶部
  scrollBehavior: () => ({ y: 0 }),
  // 组合到一起组成路由表
  routes: [...constantRoutes, ...asyncRoutes]
})
const router = createRouter()
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}
export default router
